Intro to Jelly Forest - Unity Game Guide introduces a 2D runner game with blockchain features like social sign-in, upgrades, and cosmetic items stored in a smart contract wallet.
JellyForest
, which, with a few tweaks, we were able to get a functional build from on iOS and Android.
SequenceConfig
scriptable object which you imported via the Samples menu in Package Manager during the installation stage, add your Google and Apple client ids which you added to the Builder as well as your Configuration Key under WaaSConfigKey
Settings > API Access Keys
- you want the prod
keyCanvas
, attach a Canvas Scaler
component and use the “Scale with Screen Size” UI Scale Mode. This will make it so that the LoginPanel (and any other UI elements under this Canvas) are scaled automatically when switching between build targets.LoginPanel
prefab into your Scene Hierarchy under the Canvas. This can be found in the Project window under Packages > Sequence Embedded Wallet SDK > SequenceFrontend > Prefabs
.Open
on the LoginPanel
. See our implementation below:LoginPanel
prefab in the Hierarchy so that you can edit it freely in the scene view
LoginPanel
GameObject in the HierarchyLoginPanel
GameObject in the HierarchyPrefab > Unpack Completely
LoginPage
and OpenIdAuthenticator
implementations.
The authentication works via the Open ID Connect Implicit Flow.
OpenIdAuthenticator.SignedIn
event is fired. This initiates the authorization process in SequenceLogin.ConnectToWaaS
.
SequenceWallet.OnWalletCreated
event.
SequenceConnector
via the “Useful Scripts” under Samples in the Package Manager page for the “Sequence Embedded Wallet SDK”. By default, it contains a lot of helpful starting code and acts as a useful interface to communicate with the SDK. We used it quite heavily in our integration with JellyForest.
In JellyForest, we also created a LevelLoader MonoBehaviour that loads the next scene when the SequenceWallet.OnWalletCreated
event is fired.
git clone https://github.com/0xsequence-demos/cloudflare-worker-sequence-relayer.git
then cd cloudflare-worker-sequence-relayer
git checkout permissionedMinter
pnpm install
- to install dependancieswrangler.toml
name
stringPKEY
CONTRACT_ADDRESS
PROJECT_ACCESS_KEY
- this is your prod API key from the Builder Console you retrieved earlier when setting up the SequenceConfig
scriptable objectCHAIN_HANDLE
- if you’re not sure what this is, you can see the CHAIN_HANDLE
for each respective network on the Node Gateway page of the Builder Console.pnpm dev
- this will deploy the server locally. You should see which localhost it is deployed to in the command linecurl http://localhost:8787
- substitute whichever localhost you are given. This will ping the server.Contracts
and click to open itWrite Contract
grantRole
role
enter 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6
- this is the Keccak-256 hash of MINTER_ROLE
account
paste the minter’s wallet addresswrangler deploy
- this will deploy the code to a Cloudflare Worker and give you a minting URLproof
is generated by the client sending the minting request. In the Unity SDK this is implemented by the MintingRequestProver.
PermissionedMinter.MintToken
method.
In Jelly Forest, as the player runs through the level they collect a lot of coins, these are all ERC1155 tokens. There are still a few challenges we need to solve for in order to provide our players with a great UX.
SequenceWallet
in Jelly Forest, SequenceConnector, which we used as our primary interface for communicating with the Sequence SDK in our game, creates an Inventory
.
Inventory
is used as a simple cache in our game. When first created, and when prompted, we use the Indexer to fetch all the tokens in the users wallet. From here, whenever the user earns a token, we update our cache (Inventory
) and the on-chain data.
Read the full Inventory
implementation here
SequenceConnector
GameObject and grab a reference to it in Awake.
Inventory
and add a mint transaction to the PermissionedMinterTransactionQueuer
’s queue. The PermissionedMinterTransactionQueuer
will automatically merge transactions together when possible so that you spend the least amount of money on gas fees as possible.
In Jelly Forest, we’ve configured our transaction queuer to submit transactions every time the player has a game over, but no sooner than every 30 seconds.
TransactionQueuers
can be configured to submit transactions automatically every X seconds, when promted (via function call) but no sooner than every Y seconds, or when prompted overriding any minimum time threshhold configured (Y seconds).
Here are some things to consider when determining how to configure your transaction queuers:
data
parameter, the contract will check if it received the required amount of each token id; if this passes, the contract burns the tokens and mints the requested token id to the sender (user); otherwise, the transaction fails and reverts.
We’ve given this contract minting permissions for our game contract in the Builder Console:
Contracts
and click to open itWrite Contract
grantRole
role
enter 0x9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6
- this is the Keccak-256 hash of MINTER_ROLE
account
paste the minter’s wallet addressBurnToMint
smart contract shared above has not been audited by a third party. Re-use with caution!
:::
When a user purchases an upgrade or cosmetic from the shop, we send a transaction to the BurnToMint
smart contract by adding a PurchaseShopItemQueueableTransaction to our SequenceWalletTransactionQueuer in our SequenceConnector
.
BurnToMint
contract on-chain.
We created an editor extension for our ShopItem
scriptable objects adding a button that, when pressed, will check if the minting requirements defined on-chain match what is defined in the scriptable object; if they differ, it will send a transaction to update the minting requirements in the BurnToMint
contract on-chain to match the scriptable object. The transaction is submitted via an EOA wallet created from a private key stored as an environment variable on one of our developer’s machines. This EOA wallet is the owner of this contract.
In fact, our Shop Pages actually query the smart contract every 60 seconds (and every time they open) for changes in minting requirements, updating their UI accordingly. This allows us to make live patches to our game’s economy without requiring an update!
Click on the video below
Item
a PowerUpType
and tier. Then we query our Inventory
to find the best power up of each type that the player owns.